<!DOCTYPE html>
<html class="x-admin-sm">
    <head>
        <meta charset="UTF-8">
        <title>LB-Admin1.0</title>
        {include file="header"}
    </head>
    <body>
    <div class="x-nav">
        <div class="layui-breadcrumb" style="float: left;">
            <!--<a onclick="history.back()"><i class="layui-icon layui-icon-prev"></i></a>-->
            <a>首页</a>
            <a>供应商管理</a>
        </div>
        <div style="float: right;">            
            <a onclick="xadmin.open('添加','{:url("modify")}')"><button class="layui-btn"><i class="layui-icon">&#xe61f;</i>添加</button></a>{if $user.id==1}
            <!--<button class="layui-btn layui-btn-danger" style="margin-left:5px" onclick="delAll()"><i class="layui-icon">&#xe640;</i>批量删除</button>{/if}-->
            <a class="layui-btn layui-btn-small" href="javascript:location.replace(location.href);" title="刷新">
                <i class="layui-icon layui-icon-refresh-1"></i></a>
        </div>
    </div>
    <div class="layui-fluid">
            <div class="layui-row layui-col-space15">
                <form class="layui-form layui-col-space5">
                <div class="layui-input-inline layui-show-xs-block">
                    <input class="layui-input" placeholder="关键词" name="keyword"></div>
                <div class="layui-input-inline layui-show-xs-block">
                    <button class="layui-btn"  lay-submit="" lay-filter="sreach">搜索</button>
                </div>
            </form>
                <div class="layui-col-md12">
                    <div class="layui-card">
                        <div class="layui-card-body layui-table-main">
    {empty name='data_list'}
    <blockquote class="layui-elem-quote">没 有 记 录 哦！</blockquote>
    {else}  
       <table class="layui-table layui-form">
        <thead>
        <tr>
            <th class='' style="width:20px;"><input type="checkbox" lay-filter="checkall" name="" lay-skin="primary"></th>
            <th>单位名称</th>
            <th>负责人</th>
            <th>地址</th>
            <th>电话</th>
            <th>备注</th>
            <th style="width:125px;"></th>
        </tr>
        </thead>
        <tbody>
        {foreach $data_list as $key=>$vo}
        <tr data-dbclick>
            <td><input type="checkbox" name="id" value="{$vo.id}"   lay-skin="primary"></td>
            <td>{$vo.name}</td>
            <td>{$vo.admin_name}</td>
            <td>{$vo.address}</td>
            <td>{$vo.tel}</td>
            <td>{$vo.memo}</td>
            <td>
               <a class="layui-btn layui-btn-xs" title="编辑"  onclick="xadmin.open('编辑','{:url("modify",["id"=>$vo.id])}')" href="javascript:;">编辑</a>
               <a class="layui-btn layui-btn-danger layui-btn-xs" onclick="remove(this,{$vo.id})">删 除</a>
            </td>
        </tr>
        {/foreach}
        </tbody>
    </table>
    {$page|raw}
        <script>
        function saveAdmin()
        {
            var ids = [];
            $('tbody input').each(function(index, el) {
                if($(this).prop('checked')){
                   ids.push($(this).val())
                }
            });
            if(ids.length==0)
            {
                layer.msg('请选择单位');
                return;
            }
            var formData={id:ids,user_id:$("#admin_id").val()};
            console.log(formData)
            $.post("/wadmin/shop/save",formData,function(res){
              console.log(res)
              if(res.code==1)  
              {
                  $(obj).parents("tr").remove();
                  layer.msg('已删除!',{icon:1,time:1000});
              }
              else
              {
                  layer.msg('失败');
              }
          })
        }
      layui.use(['laydate','form'], function(){
        var laydate = layui.laydate;
        var  form = layui.form;
        // 监听全选
        form.on('checkbox(checkall)', function(data){
          if(data.elem.checked){
            $('tbody input').prop('checked',true);
          }else{
            $('tbody input').prop('checked',false);
          }
          form.render('checkbox');
        }); 
      });
      function remove(obj,id)
      {
          layer.confirm('确认要删除吗？',function(index){
          $.post("/wadmin/shop/remove",{id:id},function(res){
              console.log(res)
              if(res.code==1)  
              {
                  $(obj).parents("tr").remove();
                  layer.msg('已删除!',{icon:1,time:1000});
              }
              else
              {
                  layer.msg('失败');
              }
          })
          });
          
      }
      function delAll (argument) {
        var ids = [];
        // 获取选中的id 
        $('tbody input').each(function(index, el) {
            if($(this).prop('checked')){
               ids.push($(this).val())
            }
        });
        if(ids.length==0)
        {
            layer.msg('请选择删除项');
            return;
        }
        layer.confirm('确认要删除吗？',function(index){
            $.post("/wadmin/shop/remove",{id:ids},function(res){
              console.log(res)
              if(res.code==1)  
              {
                  layer.msg('删除成功', {icon: 1});
                  $(".layui-form-checked").not('.header').parents('tr').remove();
              }
              else
              {
                  layer.msg('失败');
              }
          });
        });
      }
      </script>
    {/empty}
</div></div></div></div></div>
{include file="footer"}
